<template>
  <el-dialog
    :title="$t('batch.missionManage.form.splitDetails')"
    :visible.sync="open"
    @close="close()"
    width="80%"
    append-to-body
  >
    <div class="discountReceipt-pick-operate-box">
      <!--    <Ht-search-form-->
      <!--      :defaultEventKey="defaultEventKey"-->
      <!--      :dictMap="dictMap"-->
      <!--      :queryParams="queryParams"-->
      <!--      :outputQueryParams="queryParams"-->
      <!--      :formOptions="formOptions"-->
      <!--      :advOptions="[]"-->
      <!--      permission="batch:missionManage:view"-->
      <!--    ></Ht-search-form>-->
      <div class="operate-box-bottom">
        <div class="bottom-content">
          <ht-table
            ref="dataTable"
            :defaultEventKey="defaultEventKey"
            :initData="false"
            :multiSelect="false"
            :canHideSearch="false"
            :dictMap="dictMap"
            :reqConfig="reqConfig"
            :queryParams="queryParams"
            :tableBindColumns="tableBindColumns"
          >
            <template v-slot:shortContext="slotProps">
              <el-popover
                v-if="slotProps.row.shortContext"
                placement="top-start"
                width="300"
                trigger="hover"
                :content="slotProps.row.shortContext"
              >
                <span slot="reference">{{ $t("common.check") }}</span>
              </el-popover>
            </template>
          </ht-table>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import {
  apiSplitDetailsUrlConfig,
  cancel,
  nodeReRun,
  nodeContinueRun,
} from "@/api/batch_app/missionManage";
import { listPageMixin } from "@/libs/listPageMixin";

export default {
  name: "SplitDetails",
  mixins: [listPageMixin],
  data() {
    return {
      defaultEventKey: "sd",
      open: false,
      queryParams: {
        nodeInstanceId: "",
      },
      formOptions: [],
      reqConfig: apiSplitDetailsUrlConfig,
      // 列信息
      tableBindColumns: [
        { label: `Node ID`, prop: "nodeInstanceId" },
        {
          label: this.$t("batch.missionManage.form.splitId"),
          prop: "id",
          width: 180,
        },
        {
          label: this.$t("batch.missionManage.form.shortContext"),
          prop: "shortContext",
          customSlot: true,
        },
        {
          label: this.$t("batch.missionManage.form.startTime"),
          prop: "createTime",
          width: 180,
        },
        {
          label: this.$t("batch.missionManage.form.endTime"),
          prop: "endTime",
          width: 180,
        },
        {
          label: this.$t("batch.missionManage.form.executionTime"),
          prop: "exeTimeLength",
        },
        {
          label: this.$t("batch.missionManage.form.splitStatus"),
          prop: "status",
          dictCode: "scubb_split_status",
        },
        {
          label: this.$t("batch.missionManage.form.notificationInfo"),
          prop: "notifyMsg",
        },
        {
          label: this.$t("batch.missionManage.form.notifyStatus"),
          prop: "notifyStatus",
          dictCode: "scubb_notify_status",
        },
      ],
    };
  },
  mounted() {
    const formOptions = [
      // {
      //   type: "input",
      //   prop: "flowName",
      //   defaultAttr: {
      //     size: "small",
      //     label: "流程名称",
      //     placeholder: "请输入流程名称",
      //   },
      // }
    ];
    this.formOptions = formOptions;
  },
  methods: {
    show(nodeInstanceId = "") {
      this.queryParams.nodeInstanceId = nodeInstanceId;
      // apiSplitDetailsUrlConfig.queryUrl = `${apiSplitDetailsUrlConfig.queryUrl}?nodeInstanceId=${nodeInstanceId}`
      // apiSplitDetailsUrlConfig.exportUrl = `${apiSplitDetailsUrlConfig.exportUrl}?nodeInstanceId=${nodeInstanceId}`
      // this.queryParams.nodeCode = nodeCode;
      this.open = true;
      this.$nextTick(() => {
        this.doQuery(this.defaultEventKey);
      });
    },
    close() {
      this.open = false;
    },
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "details":
          break;
        case "reRun":
          nodeReRun(row.flowCode, row.nodeCode, row.requestId).then((res) => {
            if (res.result) {
              this.$message.success(this.$t("common.operateSuccess"));
            } else {
              this.$message.error(this.$t("common.failure"));
            }
          });
          break;
        case "nodeContinueRun":
          nodeContinueRun(row.flowCode, row.nodeCode, row.requestId).then(
            (res) => {
              if (res.result) {
                this.$message.success(this.$t("common.operateSuccess"));
              } else {
                this.$message.error(this.$t("common.failure"));
              }
            }
          );
          break;
        case "cancel":
          this.$confirm(
            this.$t("batch.missionManage.rules.cancelNode"),
            this.$t("common.warning"),
            {
              confirmButtonText: this.$t("common.confirm"),
              cancelButtonText: this.$t("common.cancel"),
              type: "warning",
            }
          )
            .then(function () {
              return cancel(row.flowCode, row.requestId);
            })
            .then(() => {
              this.doQuery(this.defaultEventKey);
              this.msgSuccess(this.$t("common.cancelSuccess"));
            })
            .catch((action) => {});
          break;
      }
    },
  },
};
</script>

<style scoped>
</style>
